﻿package tk.mystudio.web.util;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 常量工具类
 * 
 * @author jiangkunpeng
 * @since 2011-5-3 
 * @version 1.0
 */
public class KeyValueUtil {
	
	private static final Logger logger = LoggerFactory.getLogger(KeyValueUtil.class);
	
	public static List<KeyValueEntity> getList(String className) {
		List<KeyValueEntity> list = new ArrayList<KeyValueEntity>();
		try {
			Class clazz = Class.forName(className);
			String namePrefix = clazz.getSimpleName()+".";
			Field fields[] = clazz.getDeclaredFields();
			for(Field field : fields) {
				KeyValueEntity kve = new KeyValueEntity(namePrefix+field.getName(), field.get(null).toString());
				list.add(kve);
			}
		} catch (ClassNotFoundException e) {
			logger.warn("xxxxxx class {} not found!", className);
		} catch (Exception e) {
			logger.warn("xxxxxx get KeyValueEntity failed!", e);
		}
		return list;
	}
	
}
